package com.brainhealth.common.enums;

import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author wll
 */
public enum SexEnum {
    MALE("0", "男"), FEMALE("1", "女"),ALL("-1","全部");
    private final String code;
    private final String info;

    SexEnum(String code, String info) {
        this.code = code;
        this.info = info;
    }


    /**
     * 获取性别编码列表
     *
     * @return
     */
    public static List<String> getSexCodeList() {
        List<String> list = new ArrayList<>(2);
        list.add(MALE.code);
        list.add(FEMALE.code);
        return list;
    }

    /**
     * 获取性别编码列表 (全部)
     *
     * @return
     */
    public static List<String> getAllSexCodeList() {
        List<String> list = new ArrayList<>(3);
        for (SexEnum sexEnum : SexEnum.values()) {
            list.add(sexEnum.code);
        }
        return list;
    }

    /**
     * 获取性别编码获取性别描述
     *
     * @return
     */
    public static String getSexNameByCode(String code) {
        if (StringUtils.isEmpty(code)){
            return "";
        }

        for (SexEnum sexEnum : SexEnum.values()) {
            if (code.equals(sexEnum.code)){
                return sexEnum.info;
            }
        }
        return null;
    }
}
